<?php
$pageTitle = isset($pageInfo) ? $pageInfo['Content']['content_description'] :'Page Contents';
$this->Html->addCrumb('Content Pages','/admin/contents');
$this->Html->addCrumb($pageTitle);
$this->Html->scriptStart(array('inline' => false));
echo '
      $(function(){
         $(".restoreLink").click(function(event){
          var $link = $(this);
          $.TWS_Overlay("confirm", {title : "Restore confirmation", message : "Are you sure you want to restore to this version?", buttons : {ok :{onclick : function () { $.TWS_Overlay("hide"); location.href=$link.attr("href");}}}});
          event.preventDefault();
        });
      
        $(".displayContent").cluetip({splitTitle: "|", width: 800, cluetipClass: "tws", dropShadow : false, positionBy : "mouse", cursor : "default"});
      });
       ';
$this->Html->scriptEnd();
?>

<h1><?php echo $pageTitle;  ?></h1>
<?php echo $this->Session->flash();?>
<?php echo '<div id="actionLink">'.$this->Html->link('Back to list of Content Pages',array('action'=>'index', 'admin'=>true)).'</div>'; ?>

<? if (empty($records)) { echo '<p>No previous versions of this page are currently available.</p>'; }
 else {
  ?>
   <p>Up to the last <?php echo Configure::read('App.contentRestoreLimit') ?> most recent changes will be shown.</p>
   <table class="results" id="previousVersions" >
    <thead>
      <tr>
        <th width="45%">Page Content</th>
        <th width="15%">Last Modified</th>
        <th width="10%">Modified By</th>
        <th width="40%">Actions</th>
      <tr>
   </thead>
   <tbody>
      <?php foreach ($records as $rec) {
        $rec = $rec['ContentAudit'];
        $restoreLink = $this->Html->link('Restore to this version', array('controller' => 'contents', 'action' => 'restore', $rec['id']), array("title"=>"Restore to this version", "class"=>'restoreLink'));
        $previewLink = $this->Html->link('Preview this version', array('controller' => 'contents', 'action' => 'preview', 'admin'=>false, $rec['id']), array("title"=>"Preview  this version", "target"=>'new'));
        $content = $this->Html->displayPreview(($rec['info']));
        $modified = new DateTime($rec['modified']);
        echo '<tr>';
        echo '<td><div class="displayContent" title="Page Content|'.'<div class=\'ContentBody\'>'.nl2br(stripslashes(htmlentities($rec['info']))).'</div>">'.$content.'</div></td>';
        echo '<td>'.$modified->format('m/d/Y h:i:a').'</td>';
        echo '<td>'.$rec['modified_by'].'</td>';
        echo "<td>$previewLink&nbsp;&nbsp;$restoreLink</td>";
        echo '</tr>';
      }?>
   </tbody>
   </table>

 <?php } ?>

